package com.sunday.player.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.sunday.player.R;
import com.sunday.player.domain.ImageInfo;
import com.sunday.player.domain.musicData;
import com.sunday.player.interfaceutil.interface_AdapterCallback;
import com.sunday.player.util.lazyimage.getImage;

public class adapter_playlist extends ArrayAdapter<musicData> {
    
    private LayoutInflater Li;
    private interface_AdapterCallback adapterCallback;
    private getImage getImage;
    public adapter_playlist(Context context, int textViewResourceId,List<musicData> objects, interface_AdapterCallback adapterCallback) {
	super(context, textViewResourceId, objects);
	Li = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	this.adapterCallback = adapterCallback;
	getImage  = new getImage(context);
    }
    
    
    
    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
	Viewholder viewholder = null;
	View setView = convertView;
	if(setView == null){
	    setView = Li.inflate(R.layout.item_playlist, null);
	    viewholder = new Viewholder();
	    viewholder.Them  = (ImageView)setView.findViewById(R.id.imageView_Thum);
	    viewholder.Title  = (TextView)setView.findViewById(R.id.textView_title);
	    viewholder.artist  = (TextView)setView.findViewById(R.id.textView_artist);
	    viewholder.Play  = (ImageView)setView.findViewById(R.id.imageButton_play);
	    setView.setTag(viewholder);
	}else{
	    viewholder = (Viewholder)setView.getTag();
	}
	musicData MD = getItem(position);
	viewholder.Play.setOnClickListener(new OnClickListener() {
	    
	    @Override
	    public void onClick(View v) {
		adapterCallback.onItemClickCallback(position, 0, interface_AdapterCallback.Play);
	    }
	});
	viewholder.Title.setText(MD.getTitle());
	viewholder.artist.setText(MD.getArtist()+" - "+MD.getAlbum());
	getImage.addGetimage(new ImageInfo(viewholder.Them, "", MD.getAlbum_id()));
	
	return setView;
        //return super.getView(position, convertView, parent);
    }
    
    
    
    private static class Viewholder{
	ImageView Them;
	TextView  Title;
	TextView  artist;
	ImageView Play;
    }

}
